package com.sensePlusVR.utils;

import android.bluetooth.BluetoothDevice;

import java.util.Comparator;
import java.util.Map;

public class DeviceRssiSort implements Comparator<BluetoothDevice>{
	
	private Map<String, Integer> devRssiValues;
	
	public DeviceRssiSort(Map<String, Integer> devRssiValues){
		this.devRssiValues = devRssiValues;
	}

	@Override
	public int compare(BluetoothDevice device1, BluetoothDevice device2) {
		if(device1 != null && device2 != null){
			byte rssi1 = (byte) devRssiValues.get(device1.getAddress()).intValue();
			byte rssi2 = (byte) devRssiValues.get(device2.getAddress()).intValue();
			if(rssi1 < rssi2){
				return 1;
			}else if(rssi1 == rssi2){
				return 0;
			}
		}
		return -1;
	}

}
